from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse, parse_qs


class MyHTTPRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        # print(self.path)
        parsed = urlparse(self.path)
        query = parse_qs(parsed.query)
        if "code" in query:
            code = query.get("code")[0]
            state = query.get("state")[0]
            print("code:{}, state:{}".format(code, state))
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write(b"hello world")


def main():
    server = HTTPServer(('localhost', 7070), MyHTTPRequestHandler)
    server.serve_forever()

if __name__ == '__main__':
    main()